import 'package:flutter/material.dart';
import 'package:route_manager/wx_navigator.dart';

class WalletNamePage extends StatefulWidget {
  const WalletNamePage({Key key}) : super(key: key);

  @override
  _WalletNamePageState createState() => _WalletNamePageState();
}

class _WalletNamePageState extends State<WalletNamePage> {
  TextEditingController _controller = TextEditingController();
  bool isShowClear = false;

  @override
  void initState() {
    super.initState();
    _controller.text = "kaitian";
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        elevation: 0,
        title: Text("钱包名称"),
        leading: IconButton(
          icon: Icon(Icons.arrow_back),
          onPressed: () {
            // Navigator.of(context).pop();
            WXNavigator.pop(context: context);
          },
        ),
        actions: <Widget>[
          GestureDetector(
            onTap: () {
              //点击保存
            },
            child: Container(
              child: Center(child: Text("保存")),
              margin: EdgeInsets.only(right: 13),
              padding: EdgeInsets.only(left: 10, right: 10),
            ),
          )
        ],
      ),
      body: Container(
        margin: EdgeInsets.fromLTRB(20, 15, 20, 0),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              child: TextField(
                onChanged: (String value) {
                  print('---' + value);

                  setState(() {
                    if (value.length == 0) {
                      isShowClear = false;
                    } else {
                      isShowClear = true;
                    }
                  });
                },
                maxLength: 10,
                controller: _controller,
                decoration: InputDecoration(
                    // contentPadding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                    helperText: "最多可输入10个字符",
                    helperStyle: TextStyle(fontSize: 13),
                    counterText: "",
                    suffixIcon: isShowClear
                        ? GestureDetector(
                            onTap: () {
                              _controller.clear();
                              setState(() {
                                isShowClear = false;
                              });
                            },
                            child: Icon(Icons.clear))
                        : null),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
